#include <vector>
using namespace std;

double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
    vector<int> all;
    int p = 0;
    int q = 0;
    while(p < nums1.size() && q < nums2.size()){
        if(nums1[p] < nums2[q]) all.push_back(nums1[p++]);
        else all.push_back(nums2[q++]);
    }
    if(p == nums1.size()){
        while(q < nums2.size()) all.push_back(nums2[q++]);
    }else{
        while (p < nums1.size()) all.push_back(nums1[p++]);
    }
    if(all.size() % 2) return all[(all.size() - 1) / 2];
    return (double)( all[(all.size() - 1) / 2] + all[(all.size() - 1) / 2 + 1]  ) / 2;
}